'use strict';
module.exports = (app) => {
  const { STRING, INTEGER, TEXT } = app.Sequelize;
  const CaseClassify = app.model.define('w_caseClassify', {
    id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    caseId: {
      comment: '案例id',
      type: INTEGER,
    },
    classifyId: {
      comment: '分类id',
      type: INTEGER,
      allowNull: false,
    },
  });
  //创建多对多关联
  CaseClassify.associate = function () {
    app.model.Tables.Web.Case.belongsToMany(app.model.Tables.Web.Classify, {
      through: {
        model: CaseClassify,
        unique: false,
      },
      foreignKey: 'caseId',
      constraints: false,
    });

    app.model.Tables.Web.Classify.belongsToMany(app.model.Tables.Web.Case, {
      through: {
        model: CaseClassify,
        unique: false,
      },
      foreignKey: 'classifyId',
      constraints: false,
    });
  };
  return CaseClassify;
};
